package solution.linklist.StuLinkedList;

public class StuLinkedListOps {
    private StuLinkedList head = new StuLinkedList(0,"");

    public void add(StuLinkedList stuLinkedList){
        StuLinkedList temp = head;
        while (temp.next != null) {
            temp = temp.next;
        }
        temp.next = stuLinkedList;
    }

    public void list(){
        StuLinkedList temp =head.next;
        while (temp != null){
            System.out.println(temp);
            temp = temp.next;
        }
    }

    public void addByOrder(StuLinkedList stuLinkedList){
        StuLinkedList temp = head;
        boolean flg = false;
        while (true){
            if (temp.next == null) return;
            if (temp.next.no > stuLinkedList.no) break;
            if (temp.next.no == stuLinkedList.no) flg = true;
            temp = temp.next;
        }
        if (flg) System.out.println("no is existed");
        else stuLinkedList.next = temp.next;
            temp.next = stuLinkedList;
    }

    public void update(StuLinkedList stuLinkedList){
        StuLinkedList temp = head.next;
        boolean flg = false;

        while (true){
            if (temp == null) return;
            if (temp.no == stuLinkedList.no){
                flg = true;
                break;
            }
            temp = temp.next;
        }
        if (flg){
            temp.name = stuLinkedList.name;
        }else {
            System.out.println("not existed node");
        }
    }
}
